<template>
  <div class="mod-config editViewContainer">
    <split-pane class="splitPane" :min-percent='10' :default-percent='10' split="vertical">
      <template slot="paneL">
        <div class="treeViewContainer">
          <tree-view ref="treeView" :treeData="productDeviceTreeList" :checkChangedHandler="getDataList"></tree-view>
        </div>
      </template>
      <template slot="paneR">
        <table-view ref="view"
                    :searchAttrs="searchAttrs"
                    :primaryKey="primaryKey"
                    :listApiName="listApiName"
                    :deleteApiName="deleteApiName"
                    :showAttrs="showAttrs"
                    :optionWidth="240"
                    :exportPlantFunc="exportPlantFunc"
                    :exportAuthName="exportAuthName"
                    :adviceNoteFunc="adviceNoteFunc"
        >
          <template v-slot:foot="{scope}">
            <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="纸箱修改" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button type="primary" icon="el-icon-edit" size="small" @click="updateOrderDetailByBox(R.prop('row', scope))"></el-button>
            </el-tooltip>

            <el-tooltip v-if="isAuth(boxOrderAuthName)"  class="item" effect="dark" content="修改纸箱订购状态" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button type="warning" icon="el-icon-box" size="small" @click="openBoxOrderStatusDialog(R.prop('row', scope))"></el-button>
            </el-tooltip>

            <el-tooltip v-if="isAuth(boxOrderAuthNameFactory)"  class="item" effect="dark" content="修改纸箱加工状态" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button type="warning" icon="el-icon-box" size="small" @click="openBoxOrderStatusDialog(R.prop('row', scope))"></el-button>
            </el-tooltip>

            <el-tooltip style="display: inline-flex; margin-left: 10px;" class="item" effect="dark" content="上传唛头"
                        placement="bottom"
                        :hide-after="1800" :open-delay="800">
              <el-upload accept="image/*" :action="contractUploadPath" :data="{orderDetailId:scope.row.id}":on-success="updateSuccess" :show-file-list="false">
                <el-button type="success" icon="el-icon-upload2" size="small"></el-button>
              </el-upload>
            </el-tooltip>
            <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="纸箱审核" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="openBoxAuditStatusDialog(R.prop('row', scope))">
                纸箱审核
              </el-button>
            </el-tooltip>
            <el-tooltip v-if="isAuth(boxOrderAuthName)" class="item" effect="dark" content="纸箱入库" placement="bottom" :hide-after="1800" :open-delay="800">
              <el-button size="small" type="text" @click="openBoxAddStatusDialog(R.prop('row', scope))">
                纸箱入库
              </el-button>
            </el-tooltip>
          </template>
        </table-view>
      </template>
    </split-pane>

    <productinfo-add-or-update v-if="productInfoVisible" ref="productInfo"></productinfo-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <productplannotice-add-or-update v-if="productPlanNoticeVisible" ref="productPlanNotice" @refreshDataList="getDataList"></productplannotice-add-or-update>
    <deep-category-add-or-update v-if="deepCategoryInfoVisible" ref="deepCategory" ></deep-category-add-or-update>
    <model-info-add-or-update v-if="modelInfoVisible" ref="modelInfo"></model-info-add-or-update>
    <order-update-by-box v-if="orderUpdateVisible" ref="orderInfoUpdate" @refreshDataList="getDataList"></order-update-by-box>

    <el-dialog
      title="选择当前纸箱下单的状态"
      :visible.sync="boxOrderDialogVisible"
      width="40%">
      <div style="margin-bottom: 10px">
        <span> 纸箱下单状态:</span>
      </div>

      <el-radio-group v-model="boxOrderStatusRadio">
        <el-radio v-if="isAuth(boxOrderAuthName)" :label="0">未下单</el-radio>

        <el-radio v-if="isAuth(boxOrderAuthName)" :label="2">已下单</el-radio>

        <el-radio v-if="isAuth(boxOrderAuthNameFactory)" :label="5">正在加工</el-radio>

        <el-radio v-if="isAuth(boxOrderAuthNameFactory)" :label="7">加工完成</el-radio>

        <el-radio v-if="isAuth(boxOrderAuthName)" :label="10">入库完成</el-radio>

        <el-radio v-if="isAuth(boxOrderAuthName)" :label="15">改用托盘</el-radio>

        <el-radio v-if="isAuth(boxOrderAuthName)" :label="20">来料加工</el-radio>

      </el-radio-group>

      <div style="margin-top: 10px; margin-bottom: 10px">
        <span> 连体格挡下单状态:</span>
      </div>

      <el-radio-group v-model="boxBlockOrderStatusRadio">
        <el-radio :label="0">未订购</el-radio>

        <el-radio :label="1">已订购</el-radio>


      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="boxOrderDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyBoxOrderStatus">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="修改损耗数量"
      :visible.sync="orderIssuesNumberVisible"
      width="30%">
      <el-input-number v-model="orderIssuesNumber">
      </el-input-number>
      <span slot="footer" class="dialog-footer">
        <el-button @click="orderIssuesNumberVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderIssuesNumber">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="纸箱审核状态"
      :visible.sync="boxAuditDialogVisible"
      width="30%">
      <el-radio-group v-model="boxAuditStatusRadio">
        <el-radio :label="0">未审核</el-radio>

        <el-radio :label="1">已审核</el-radio>

        <el-radio :label="2">驳回，修改</el-radio>

      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="boxAuditDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyBoxAuditStatus">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="纸箱入库详情"
      :visible.sync="boxAddDialogVisible"
      width="30%">
      <el-input v-model="pieceNumber" placeholder="纸箱只数"> </el-input>
      <el-input v-model="boxNumber" placeholder="纸箱数量"> </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="boxAddDialogVisible = false">取 消</el-button>
<!--        <el-button type="primary" @click="modifyBoxAddStatus">确 定</el-button>-->
      </span>
    </el-dialog>

    <el-dialog
      title="批量制定发货通知计划"
      :visible.sync="orderPlanNoticeVisible"
      :fullscreen="true"
      ref="multipleDialogByBox"
      :before-close="handleClose"
    >

      <el-form
        ref="dataForm"
        label-width="120px"
        label-position="left"
        style="margin-left:30px"
      >

        <el-form-item label="发货日期" style="width: 400px">
          <el-date-picker
            v-model="dayTime"
            align="right"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>

        </el-form-item>



      </el-form>

      <el-table
        :data="tableListData"
        border
        style="display: inline-block">

        <el-table-column
          prop="orderNo"
          label="订单编号"
          align="center"
          width="170"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" readOnly  v-model="scope.row.orderNo" placeholder="订单编号"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop="productNo"
          label="产品名称"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" readOnly  v-model="scope.row.productNo" placeholder="产品名称"></el-input>
          </template>
        </el-table-column>


        <el-table-column
          prop="productWeight"
          label="克重"
          width="130"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0"  v-model="scope.row.productWeight" placeholder="克重"></el-input-number>
          </template>
        </el-table-column>


        <el-table-column
          prop="bodySize"
          label="尺寸"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" :min="0"  v-model="scope.row.bodySize"  placeholder="尺寸"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="parryNumber"
          label="格挡"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.parryNumber" placeholder="格挡"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="spacerNumber"
          label="垫片"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.spacerNumber" placeholder="垫片"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="pieceNumber"
          label="只数"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.pieceNumber" placeholder="只数"></el-input-number>
          </template>
        </el-table-column>
        <el-table-column
          prop="boxNumber"
          label="数量"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.boxNumber" placeholder="数量" @change="numberChangedHandle(scope.$index)"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="boxPrice"
          label="价格"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.boxPrice" placeholder="价格" @change="numberChangedHandle(scope.$index)"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="amount"
          label="金额"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.amount" placeholder="金额"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="remark"
          label="备注"
        >
          <template slot-scope="scope">
            <el-input type="textarea" controls-position="right" size="small" :min="0"  v-model="scope.row.remark" placeholder="备注"></el-input>
          </template>
        </el-table-column>

      </el-table>



      <span slot="footer" class="dialog-footer">
        <el-button @click="orderPlanNoticeVisible = false">取 消</el-button>
        <el-button type="primary" @click="multipleSaveBoxAdd()">确 定</el-button>
      </span>

    </el-dialog>
  </div>
</template>

<script>
import tableView from '@/components/tableView'
import basicMixins from '@/utils/commonViewMixins'
import ProductinfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'
import ProductplannoticeAddOrUpdate from '@/views/modules/product/productplannotice-add-or-update'
import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update'
import DeepCategoryAddOrUpdate from '@/views/modules/deep/deepcategory-add-or-update'
import {mRequest} from '@/utils/request'
import {exportHandle, isAuth} from '@/utils'
import ModelInfoAddOrUpdate from '@/views/modules/model/modelinfo-add-or-update'
import treeView from '@/components/treeView'
import {getUrl} from '@/utils/request'
import OrderUpdateByBox from './orderdetail-update-by-box'
import multipleDialogByBox from '@/components/multipleDialogByBox'

export default {
  mixins: [basicMixins],
  data() {
    return {
      isAuth: isAuth,
      status: 0,
      bigMouth: '',
      boxOrderStatusRadio: 0,
      boxBlockOrderStatusRadio: 0,
      orderIssuesNumber: 0,
      boxAuditStatusRadio: 0,
      dialogVisible: false,
      modelInfoVisible: false,
      orderIssuesNumberVisible: false,
      boxOrderDialogVisible: false,
      productPlanNoticeVisible: false,
      productInfoVisible: false,
      clientInfoVisible: false,
      deepCategoryInfoVisible: false,
      bigMouthVisible: false,
      orderPlanNoticeVisible: false,
      boxAuditDialogVisible: false,
      boxAddDialogVisible: false,
      orderUpdateVisible: false,
      productDeviceList: [],
      deviceIdList: [],
      orderDetailList: [],
      productInfoList: [],
      modelInfoList: [],
      tableListData: [],
      deepCategoryList: [],
      productDeviceTreeList: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      pieceNumber:0,
      boxNumber:0,
      sysUserList: [],
      deviceId: '',
      onlineTime: '',
      dayTime: '',
      searchAttrs: {
        productNo: {
          label: '产品名称',
          placeholder: '请输入产品名称',
        },
        boxOrderStatus: {
          label: '纸箱下单状态',
          clearable: true,
          placeholder: '请选择导出状态',
          type: 'list',
          list: [],
        },

        createUser: {
          label: '业务',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请选择业务人员',
          querySearchApiName: 'systemApi/listSaleUser'
        },
        deviceId: {
          type: 'func',
          dataFunc: () => {
            return this.$refs.treeView.$refs.treeForm.getCheckedKeys()[0]
          }
        },
        clientId: {
          label: '客户名称',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请输入客户名称',
          querySearchApiName: 'clientApi/getClientList'
        },
        boxAudit: {
          label: '纸箱审核',
          clearable: true,
          placeholder: '请选择纸箱审核状态',
          type: 'list',
          list: [],
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      primaryKey: 'id',
      listApiName: 'orderApi/listOrderDetailByDeviceIdAndBoxOrderStatus',
      deleteApiName: 'orderApi/deleteOrderDetail',
      importApiName: 'orderApi/importOrderDetail',
      saveAuthName: 'order:orderdetail:save',
      deleteAuthName: 'order:orderdetail:delete',
      boxOrderAuthName: 'order:orderdetail:boxOrder',
      exportAuthName: 'order:orderdetail:boxOrder',
      boxOrderAuthNameFactory: 'order:orderdetail:boxOrderFactory',
      contractUploadPath:  getUrl(`systemApi/uploadBoxPackImageByOrderDetailId`, {token: this.$cookie.get('token')}),
      showAttrs: {
        orderNo: {
          label: '订单编号',
          width: 100,
          type: 'labelWithStatus',
          statusAttr: 'messageStatus',
          items: [
            {value: 0, text: '未读', tagType: 'danger'}
          ]
        },
        status: {
          label: '上机状态',
          type: 'radio',
          width: 85,
          items: [
            {value: -1, text: '预排产',tagType: 'danger'},
            {value: 0, text: '挂起', tagType: 'info'},
            {value: 1, text: '暂时下线', tagType: 'warning'},
            {value: 2, text: '加急', tagType: 'warning'},
            {value: 3, text: '正常', tagType: 'primary'},
            {value: 4, text: '生产中', tagType: 'primary'},
            {value: 5, text: '生产完成', tagType: 'success'},
            {value: 10, text: '出库中', tagType: 'warning'},
            {value: 11, text: '出库完成', tagType: 'success'},
            {value: 30, text: '计划上线中', tagType: 'success'},
            {value: 32, text: '计划加急', tagType: 'danger'},
            {value: 90, text: '客户待确认', tagType: 'info'},
            {value: 99, text: '取消', tagType: 'danger'}
          ]
        },
        productNo: {
          label: '产品编号',
          width: 100,
          type: 'linkLabel',
          routerName: 'product-productinfo',
          searchKey: 'productNo'
        },
        bottleLength: {label: '长度'},
        bottleWeight: {label: '宽度'},
        bottleHeight: {label: '高度'},
        headNeckHeight: {label: '头径高度'},
        boxAudit: {
          label: '纸箱审核',
          type: 'radio',
          items: [
            {value: 0, text: '未审核', tagType: 'danger'},
            {value: 1, text: '已审核',tagType: 'success'}
          ]
        },
        orderProductNumberStr: {label: '订单数量'},
        specialMark: {
          label: '箱唛',
          type: 'radio',
          items: [
            {text: '普英唛', value: 0, tagType: 'success'},
            {text: '专用唛', value: 1},
            {text: '普英唛+H', value: 2,tagType: 'warning'}
          ]
        },
        boxPackImage: {label: '箱唛图片（侧）', type: 'image'},
        boxPackImageFront: {label: '箱唛图片（正）', type: 'image'},
        boxSupplyWay: {
          label: '包装供应',
          type: 'radio',
          items: [
            {value: 0, text: '纸箱', tagType: 'success'},
            {value: 1, text: '托盘'},
            {value: 2, text: '客供', tagType: 'danger'}
          ]
        },
        boxOrderStatus: {
          label: '纸箱下单',
          type: 'radio',
          items: [
            {text: '未下单', value: 0, tagType: 'danger'},
            {text: '已下单', value: 2,tagType: 'success'},
            {text: '正在加工', value: 5},
            {text: '正在加工', value: 10},
            {text: '改用托盘', value: 15 },
            {text: '自供', value: 20}
          ]
        },
        boxBlockOrderStatus: {
          label: '连体格挡',
          type: 'radio',
          items: [
            {text: '未订购', value: 0, tagType: 'info'},
            {text: '已订购', value: 1,tagType: 'success'}
          ]
        },
        onlineTime: {label: '预上线时间', type: 'date', width: 95},
        bottleOutDiameter: {label: '瓶口外径'},
        productWeightStr: {label: '订单克数'},
        productVolumeStr: {label: '订单容量'},
        bottleCraft: {label: '工艺'},

        remark: {label: '备注', width: 140},


        salesperson: {label: '业务员'},

        deepTypeStr: {label: '深加工'},

        clientName: {label: '客户',width: 150},
        deliveryTime: {label: '交货时间', type: 'date', width: 95},
        bottleCapSuit: {
          label: '瓶盖套装',
          type: 'radio',
          items: [
            {value: 0, text: '无', tagType: 'danger'},
            {value: 1, text: '有'}
          ]
        },
        bottleInDiameter: {label: '瓶口内径'},


        customerProductStyle: {
          label: '客户样品',
          type: 'radio',
          items: [
            {value: 0, text: '无', tagType: 'danger'},
            {value: 1, text: '有'}
          ]
        }
      }
    }
  },
  mounted() {
    this.productDeviceTreeListInit()
  },
  methods: {

    productDeviceTreeListInit() {
      mRequest('productApi/getProductDeviceListByParent', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
        const productDeviceTreeList = [{
          id: '',
          name: '生产线信息',
          nodeType: 0,
          children: []
        }]

        productDeviceTreeList[0].children = this.productDeviceList
        this.productDeviceTreeList = productDeviceTreeList;
      })

      this.searchAttrs['boxOrderStatus'].list = [
        {
          id: 0, name: '未下单'
        },
        {
          id: 2, name: '已下单'
        },
        {
          id: 5, name: '正在加工'
        }, {
          id: 10, name: '入库完成'
        }, {
          id: 15, name: '改用托盘'
        },
        {
          id: 20, name: '来料加工'
        },
      ]
      this.searchAttrs['boxAudit'].list =[
        {
          id: 0, name: '未审核'
        },
        {
          id: 1, name: '已审核'
        }
      ]
    },
    openOrderStatusDialog(order) {
      this.dialogVisible = true
      this.modifyOrder = order
      const {status} = order

      this.status = status
    },
    modifyOrderStatus() {
      if (this.modifyOrder.status === this.status) {
        return
      }
      this.modifyOrder.status = this.status

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.status = 0
        this.dialogVisible = false
        this.getDataList()
      })
    },
    modifyBigMouth() {
      if (this.modifyOrder.bigMouth === this.bigMouth) {
        return
      }
      this.modifyOrder.bigMouth = this.bigMouth

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.bigMouth = ''
        this.bigMouthVisible = false
        this.getDataList()
      })
    },
    openBigMouthDialog(order) {
      this.bigMouthVisible = true
      this.modifyOrder = order
      const {bigMouth} = order

      this.bigMouth = bigMouth
    },

    openBoxOrderStatusDialog(order) {
      this.boxOrderDialogVisible = true
      this.modifyOrder = order
      const {boxOrderStatus,boxBlockOrderStatus} = order
      this.boxOrderStatusRadio = boxOrderStatus
      this.boxBlockOrderStatusRadio = boxBlockOrderStatus
    },
    modifyBoxOrderStatus(){

      this.modifyOrder.boxOrderStatus = this.boxOrderStatusRadio
      this.modifyOrder.boxBlockOrderStatus = this.boxBlockOrderStatusRadio

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.boxOrderStatusRadio = 0
        this.boxBlockOrderStatusRadio = 0
        this.boxOrderDialogVisible = false
        this.getDataList()
      })
    },
    modifyOrderIssuesNumber() {
      if (this.modifyOrder.orderIssuesNumber === this.orderIssuesNumber) {
        return
      }
      this.modifyOrder.orderIssuesNumber = this.orderIssuesNumber

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.orderIssuesNumber = 0
        this.orderIssuesNumberVisible = false
        this.getDataList()
      })
    },
    openProductPlanNotice(id) {
      this.productPlanNoticeVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productPlanNotice)) {
          this.$refs.productPlanNotice.init(null, {orderDetailId: id}, () => {
            this.$router.push({name: 'product-productplannotice'})
          })
        }
      })
    },
    openProductInfoDialog(cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {
          this.$refs.productInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openClientInfoDialog(cb) {
      this.clientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.clientInfo)) {
          this.$refs.clientInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openDeepCategoryInfoDialog(cb){
      this.deepCategoryInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.deepCategory)) {
          this.$refs.deepCategory.init(null, {status: 1}, cb)
        }
      })
    },
    openOrderIssuesNumberDialog(order){
      this.orderIssuesNumberVisible = true
      this.modifyOrder = order
      const {orderIssuesNumber} = order

      this.orderIssuesNumber = orderIssuesNumber
    },
    openBoxAuditStatusDialog(order) {
      this.boxAuditDialogVisible = true

      this.modifyOrder = order
      const {boxAudit} = order

      this.boxAuditStatusRadio = boxAudit
    },
    modifyBoxAuditStatus(){
      if (this.R.equals(this.modifyOrder.boxAudit,this.boxAuditStatusRadio )) {
        this.modifyOrder = null
        this.boxAuditStatusRadio = 0
        this.boxAuditDialogVisible = false
        return
      }
      this.modifyOrder.boxAudit = this.boxAuditStatusRadio

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.boxAuditStatusRadio = 0
        this.boxAuditDialogVisible = false
        this.getDataList()
      })
    },
    openBoxAddStatusDialog() {
      this.boxAddDialogVisible = true
    },
    modifyBoxAddStatus() {

    },


    exportPlantFunc(rows){

      const ids = rows.map(item => {
        return item[this.primaryKey]
      })
      this.$confirm('是否直接导出纸箱生产计划?', '提示', {
        confirmButtonText: '导出',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        exportHandle('orderApi/downloadUpdateBoxOrderStatus', {orderDetailIdList: ids})
        this.getDataList()
      }).catch(() => {
        this.$message({
          message: '操作成功',
          type: 'success',
          duration: 1500,
          onClose: () => {
            this.getDataList()
            this.$emit('refreshDataList')
          }
        })
      })

    },

    initSysUserInfoList() {
      mRequest('systemApi/listAllUser', {}, (res) => {
        this.sysUserList = this.R.pathOr([], ['data', 'list'], res)
      })
    },

    initProductDeviceListByParent() {
      mRequest('productApi/getProductDeviceListByParent', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initOrderDetailList() {
      mRequest('orderApi/getOrderDetailList', {}, (res) => {
        this.orderDetailList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initProductInfoList() {
      mRequest('productApi/getProductInfoList', {}, (res) => {
        this.productInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initDeepCategoryList(attrName = '') {
      mRequest('deepApi/deepCategoryList', {}, (res) => {
        this.deepCategoryList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initModelInfoList(attrName = 'modelInfoId') {
      mRequest('modelApi/getModelInfoList', {}, (res) => {
        this.modelInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    downloadUpdateBoxSupplyWayStatus() {


    },
    updateSuccess(response){
      const url = this.R.prop('imageUrl', response) || this.R.prop('designUrl', response)

      if (!this.R.isNil(url)) {
        this.getDataList()
      }

    },
    updateOrderDetailByBox(param){
      this.orderUpdateVisible = true

      this.$nextTick(() => {

        if (!this.R.isNil(this.$refs.orderInfoUpdate)) {
          this.$refs.orderInfoUpdate.init(param.id, param,null)
        }
      })
    },
    adviceNoteFunc(rows) {
      this.dayTime = ''

      this.tableListData = []
      for (let i = 0; i < rows.length; i++) {
        let _obj = {
          'orderDetailId': this.R.prop('id', rows[i]),
          orderNo: this.R.prop('orderNo', rows[i]),
          bodySize: this.R.prop('bodySize', rows[i]),
          pieceNumber: this.R.prop('pieceNumber', rows[i]),
          productNo : this.R.prop('productNo', rows[i]),
          boxInfoId : this.R.prop('boxInfoId', rows[i]),
          productWeight : this.R.prop('productWeight', rows[i]),
          unitPrice : this.R.prop('lightGlassPrice', rows[i]),
          orderProductNumber: this.R.prop('orderProductNumber', rows[i]),
          putInStorageNumber : this.R.prop('putInStorageNumber', rows[i]),
          leaveStorageNumber : this.R.prop('leaveStorageNumber', rows[i]),
          weightInfo : this.R.prop('weightInfo', rows[i]),
          deliveryAddress: this.R.prop('deliveryAddress', rows[i]),
          contractOrderId: this.R.prop('contractOrderId', rows[i]),
          productId: this.R.prop('productId', rows[i]),
          clientId : this.R.prop('clientId', rows[i])
        }
        this.tableListData.push(_obj)
      }
      this.orderPlanNoticeVisible=true

    },
    numberChangedHandle(index) {
      const boxNumber = this.R.propOr(0, 'boxNumber', this.tableListData[index])

      const boxPrice = this.R.propOr(0, 'boxPrice', this.tableListData[index])

      let amount= Number(boxNumber)  * Number(boxPrice)

      this.tableListData[index].amount =  amount.toFixed(2);
    },
    multipleSaveBoxAdd() {
      console.log(JSON.stringify(this.tableListData))
      let obj={
        'dayTime': this.dayTime,
        'boxAddType': 2,
        'tableListData': this.tableListData
      }
      mRequest('boxApi/multipleSaveBoxAdd', obj,(res => {
        let data = res.data

        if (data && data.code == 0) {
          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.orderPlanNoticeVisible = false
              this.loading = false
              this.getDataList()
              this.$emit('refreshDataList')
            }
          })

        } else {
          this.$message.error(data.msg)
          this.loading = false
        }
      }))
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {
        });
    },
  },
  components: {
    ProductplannoticeAddOrUpdate,
    ProductinfoAddOrUpdate,
    ModelInfoAddOrUpdate,
    ClientInfoAddOrUpdate,
    DeepCategoryAddOrUpdate,
    OrderUpdateByBox,
    multipleDialogByBox,
    treeView,
    tableView
  }
}
</script>
